package cn.com.fattiger.framework.cms.admin.common.dao;

import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.transaction.annotation.Transactional;

import cn.com.fattiger.framework.cms.admin.common.model.Version;

/**
 * 
 * @author fattiger.xiaoyang
 * @date 2016/05/05
 */
public interface VersionRepository extends PagingAndSortingRepository<Version,Integer>,JpaSpecificationExecutor<Version> {

	@Modifying
	@Transactional  
	@Query("update Version v set v.status = ?1 where v.id = ?2")
	int updateStauts(Integer status, Integer id);
	
	@Modifying
	@Transactional  
	@Query("update Version v set v.changeLog = ?1 where v.id = ?2")
	int updateChangeLog(String changeLog, Integer id);
	
	@Query("select max(versionCode) from Version v where v.appKey = ?1")
	Integer findVersionCode(String appKey);
	
	@Query("select max(patchCode) from Version v where v.appKey = ?1 and v.versionCode = ?2")
	Integer findPatchCode(String appKey, Integer versionCode);
}
